﻿using Sunisoft.IrisSkin;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;

namespace comCtrl
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            List<string> names = new List<string>();
            List<string> fullNames = new List<string>();
            Dictionary<string,string> dict = new Dictionary<string,string>();
            FileInfo[] fileInfos = new DirectoryInfo("Skins").GetFiles();
            foreach(FileInfo f in fileInfos)
            {
                names.Add(f.Name);
                fullNames.Add(f.FullName);
                dict.Add(f.Name, f.FullName);
            }
            //textBox1.Lines = names.ToArray();
            //textBox2.Lines = fullNames.ToArray();

            textBox1.Lines = dict.Keys.ToArray();
            textBox2.Lines= dict.Values.ToArray();


            skinEngine1.SkinFile = fullNames.FirstOrDefault();

            comboBox1.DataSource = fileInfos;
            listBox1.DataSource = fileInfos;

            // 内部元素的间隔，全部是10
            listView1.Margin = new Padding(10);
            
            for (int i = 0; i < 10; i++)
            {
                ListViewItem lvi = new ListViewItem();
                lvi.Text = "节点" + i;
                lvi.ImageIndex = 0;
                listView1.Items.Add(lvi);
            }

            // throw new System.NotImplementedException();
            for (int i = 0; i < 10; i++)
            {
                TreeNode parent = new TreeNode();
                parent.Text = "父节点" + i;
                parent.ImageIndex = 0;

                for (int j = 0; j < 5; j++)
                {
                    TreeNode child = new TreeNode();
                    child.Text = "子节点" + j;
                    child.ImageIndex = 1;
                    parent.Nodes.Add(child);

                }
                treeView1.Nodes.Add(parent);
            }
        }

        private void listView1_ItemActivate(object sender, EventArgs e)
        {
            //int count = listView1.SelectedItems.Count;
            //if(count == 1)
            //{
            //    ListViewItem listViewItem = listView1.SelectedItems[0];
            //    MessageBox.Show(listViewItem.Text);
            //}
        }

        private void listView1_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
        {
            int count = listView1.SelectedItems.Count;
            if (count == 1)
            {
                ListViewItem listViewItem = listView1.SelectedItems[0];
                int index = listView1.Items.IndexOf(listViewItem);
                // MessageBox.Show(listViewItem.Text);

                ItemForm itemForm = new ItemForm();
                itemForm.StartPosition = FormStartPosition.CenterParent;

                itemForm.Size = new Size(400, 200);
                itemForm.setData(index,listViewItem.Text);
                itemForm.ShowDialog(this);

            }
        }

        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {
            // throw new System.NotImplementedException();

            TreeNode node = e.Node;
            
            ItemForm itemForm = new ItemForm();
            itemForm.StartPosition = FormStartPosition.CenterParent;
            itemForm.Size = new Size(400, 200);
            itemForm.setData(node.Index,node.Text);
            itemForm.ShowDialog(this);
        }

        /// <summary>
        /// 选择皮肤
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            FileInfo v = (FileInfo)comboBox1.Items[comboBox1.SelectedIndex];
            skinEngine1.SkinFile = v.FullName;
        }
    }
}